import { test, expect } from 'bun:test'
/* 自行创建 */
import { scriptToken, webhookURL } from './const-value.ignore'
import { initRemoteCallWpsjsGlobal } from '../index'

test('视图 创建', async () => {
  const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, printLog: true })
  const info = await wpsjsGlobal.Application.View.CreateView({
    SheetId: 1,
    Name: '表格4',
    ViewType: 'Grid',
  }).execution()
  const keys = [
    'id',
    'name',
    'recordsCount',
    'type',
  ]
  expect(Object.keys(info)).toEqual(expect.arrayContaining(keys))
})

test('视图 获取', async () => {
  const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, printLog: true })
  const infoArray = await wpsjsGlobal.Application.View.GetViews({ SheetId: 1 }).execution()
  const info = infoArray[0]
  const keys = [
    'id',
    'name',
    'recordsCount',
    'type',
  ]
  expect(Object.keys(info)).toEqual(expect.arrayContaining(keys))
})

test('视图 更新', async () => {
  const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL })
  const result = await wpsjsGlobal.Application.View.UpdateView({ SheetId: 1, ViewId: 'H', Name: `表格${Date.now()}` }).execution()
  expect(result).toHaveProperty('id')
})

test('视图 删除', async () => {
  const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL })
  const info = await wpsjsGlobal.Application.View.DeleteView({ SheetId: 1, ViewId: 'G' }).execution()
  expect(info).toHaveProperty('id')
})


